//files
AddCSLuaFile("cl_init.lua");
AddCSLuaFile("shared.lua");

include("shared.lua");

AccessorFunc( ENT, "m_Flaming", "Flaming", FORCE_BOOL );

ENT.ClusterCount = 15;

//when initializing
function ENT:Initialize()

	self.Entity:SetModel("models/props_junk/Rock001a.mdl");

	self.Entity:PhysicsInit(SOLID_VPHYSICS);
	self.Entity:SetMoveType(MOVETYPE_VPHYSICS);
	self.Entity:SetSolid(SOLID_VPHYSICS);

	//physics object
	local Physics = self.Entity:GetPhysicsObject();

	//if valid
	if ValidEntity(Physics) then

		//wake
		Physics:Wake();

	else

		//if not then remove
		self.Entity:Remove();

	end

end

function ENT:SetFlaming( b )
	
	self.m_Flaming = b;
	
	if( b ) then
		
		self:Ignite( 60, 32 );
		
	end
	
end

function ENT:Explode( clusters )
	
	if( clusters ) then
		
		for i = 1, self.ClusterCount do
			
			local ent = ents.Create( self.ClassName );
			
			if( IsValid( ent ) ) then
				
				ent:SetPos( self:GetPos( ) + vector_up * 3 );
				ent:SetOwner( self:GetOwner( ) );
				
				ent:Spawn( );
				ent:Activate( );
				
				local physics = ent:GetPhysicsObject( );
				
				if( IsValid( physics ) ) then
					
					local direction = VectorRand( ):GetNormal( );
					direction.z = math.abs( direction.z * 5 );
					
					physics:ApplyForceCenter( direction * math.random( 2000, 3000 ) );
					
				end
				
				timer.Simple( i * 0.3 + math.random( 0.1, 0.2 ), ent.Explode, ent, false );
				
			end
			
		end
		
	end
	
	local fx = EffectData( );
	
	fx:SetStart( self:GetPos( ) );
	fx:SetOrigin( self:GetPos( ) );
	fx:SetScale( 1 )
	
	util.Effect( "Explosion", fx );
	
	util.BlastDamage( self.Entity, self.Entity:GetOwner(), self:GetPos( ), 230, 90 );
	
	util.Decal( "Scorch", self:GetPos( ) + vector_up, self:GetPos( ) - vector_up );
	
	self:Remove( );
	
end